gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390
gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390vstinner merged 4 commits intopython:mainfrom
Conversation
Modules/posixmodule.c
Outdated
| static bool | ||
| path_is_fd(const path_t *path) | ||
| { | ||
| return path->allow_fd && path->object != NULL && PyIndex_Check(path->object); |
There was a problem hiding this comment.
Is the problem really with the check or with is it with the converter?
There was a problem hiding this comment.
Instead of checking path->object type (PyIndex_Check()), I would prefer adding a path_t.is_fd member and modify path_converter() to set this member.
|
Other functions have the same issues, even if they don't crash:
On Linux (with the glibc), most functions fail with This list are functions using |
…onGH-145390) (cherry picked from commit 5c3a47b) Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
…onGH-145390) (cherry picked from commit 5c3a47b) Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
|
GH-145432 is a backport of this pull request to the 3.13 branch. |
|
GH-145433 is a backport of this pull request to the 3.14 branch. |
|
Merged, thanks for your contribution @aisk. I'm working on a fix for the other affected functions. |
|
I wrote #145439 to fix other os functions. |
We currently test whether
path_t.fdis -1 to decide if the argument should be treated as an fd or as a path, and then callfpathconf()orpathconf()according to it.In the original issue, we passing -1 caused the code incorrectly treats the argument as a real path. But,
path->narrowis NULL, so callingpathconf()on it will crash the interpreter.This change adds a helper that checks whether the original argument is index-like to determine if it's an fd, so we can correctly the behavior and avoid the crash.
There are other
osfunctions that acceptpath_tand may have the same issue. Since that is outside the scope of the original issue, I think we should fix those in a separate PR.os.pathconf(-1, 1)#145335